package com.moli.iov.down.command.mq.kafka;

import com.moli.iov.producer.KafkaProducerServer;
import com.moli.iov.protocol.codec.DataWrapper;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Component;

/**
 * <p>
 * kafka生产者  命令下发
 * </p>
 *
 * @author zql
 * @since 2019/9/16 12:27
 */
@Component("kafkaProducer")
public class KafkaProducer {

    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private KafkaProducerServer kafkaProducerServer;

    @Value("${kafka.down.topic}")
    private String topic;

    @Autowired
    private TaskExecutor taskExecutor;

    /**
     * 推送数据
     * @param vin
     * @param dataWrapper
     */
    public void send(String vin, DataWrapper dataWrapper){
        taskExecutor.execute(()->{
            logger.info("[下行报文] Kafka推送数据 vin：{}  allDtata：{}", vin, dataWrapper);
            Map<String, Object> res = kafkaProducerServer.sndMesForTemplate(topic, vin, dataWrapper);
            logger.info("[下行报文] Kafka 推送数据 结果返回：{}", res);
        });
    }
}
